/**
 * Created by guoshuyu on 2017/11/12.
 */
import React, {Component} from 'react';
import {
    Text,
    View,
    BackHandler
} from 'react-native';
import styles, {screenWidth, screenHeight} from "../../style/index"
import * as Constant from "../../style/constant"
import Modal from 'react-native-modalbox';
import Spinner from 'react-native-spinkit';
import {Actions} from "react-native-router-flux";

interface LoadingModalProps {
    text: string,
    backExit?: boolean,
}

/**
 * 加载中Modal
 */
class LoadingModal extends Component<LoadingModalProps> {
    static defaultProps = {
        text: "加载中...",
        backExit: true
    };
    loginModal: Modal;

    constructor(props: LoadingModalProps) {
        super(props);
    }

    onOpen = () => {
        if (this.loginModal)
            this.loginModal.open();
    }

    onClose = () => {
        this.loginModal.close();
        return true;
    }

    render() {
        return (
            <Modal ref={loginModal => this.loginModal = loginModal}
                   style={[{height: screenHeight, width: screenWidth, backgroundColor: "#F0000000"}]}
                   position={"center"}
                   backButtonClose={false}
                   swipeToClose={this.props.backExit}
                   backdropOpacity={0.8}>
                <View style={[styles.centered, {flex: 1}]}>
                    <View>
                        <Spinner style={[styles.centered]}
                                 isVisible={true}
                                 size={50} type="9CubeGrid"
                                 color="#FFFFFF"/>
                        <Text style={styles.normalTextWhite}>{this.props.text}</Text>
                    </View>
                </View>
            </Modal>
        )
    }
}


export default LoadingModal;